package com.prs.crm.dao.sale.impl;

import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.prs.crm.dao.impl.BaseDaoImpl;
import com.prs.crm.dao.sale.SaleInvoiceDao;
import com.prs.crm.domain.sale.SaleInvoice;
import com.prs.crm.domain.sale.SalesStoreOut;

public class SaleInvoiceDaoImpl extends BaseDaoImpl<SaleInvoice> implements SaleInvoiceDao{

	
	@SuppressWarnings("unchecked")
	public int getSaleOutInvoice(final SalesStoreOut storeout)
	{
		return (Integer)this.getHibernateTemplate().execute(
				new HibernateCallback()
				{
					public Object doInHibernate(Session session) throws HibernateException {
			        	Criteria criteria = session.createCriteria(SaleInvoice.class);
			        	criteria.add(Restrictions.eq("storeOutBill", storeout));
			        	criteria.setProjection(Projections.rowCount());
			        	return criteria.uniqueResult();
			        }   
				}
		);
	}
}
